#include "MovingObject.h"
#include "EventHandler.h"
#include "ObjectTypes.h"

MovingObject::MovingObject()
{
	speedConstant = 0.00000005;
	
	// OBJECTTYPE
	setObjectType(MOVING_OBJECT);
	isMoving = false;
	startMoving = false;
}

int MovingObject::setIsMoving(bool state)
{
    isMoving = state;
    return 0;
}

bool MovingObject::getIsMoving()
{
    return isMoving;
}


f32 MovingObject::getSpeedConstant()
{
	return speedConstant;
}

int MovingObject::setSpeedConstant(f32 newSpeedConstant)
{
	speedConstant = newSpeedConstant;
	return 0;
}

int MovingObject::setMovementInfo(core::vector3df startPos, core::vector3df destinationPos, core::vector3df moveSpeed, f32 timesMoved, f32 timesToMove)
{
    m_MovementInfo.startPos = startPos;
    m_MovementInfo.destinationPos = destinationPos;
    m_MovementInfo.moveSpeed = moveSpeed;
    m_MovementInfo.timesMoved = timesMoved;
    m_MovementInfo.timesToMove = timesToMove;
    return 0;
}

bool MovingObject::setMovementInfo(MovementInfo* passedMovementInfo)
{
	m_MovementInfo = *passedMovementInfo;
	return true;
}
MovementInfo* MovingObject::getMovementInfo()
{
    return &m_MovementInfo;
}

bool MovingObject::setStartMoving(bool passedStartMoving)
{
    startMoving = passedStartMoving;
    return true;
}

bool MovingObject::getStartMoving()
{
    return startMoving;
}

void MovingObject::stopMoving()
{
	startMoving = false;
	isMoving = false;
	setAnimation(scene::EMAT_STAND, true);
}

void MovingObject::setAnimation(scene::EMD2_ANIMATION_TYPE animationType, bool loopMode)
{
	scene::IAnimatedMeshSceneNode* node = reinterpret_cast<scene::IAnimatedMeshSceneNode*>(getNode());
	reinterpret_cast<scene::IAnimatedMeshSceneNode*>(getNode())->setLoopMode(loopMode);
	reinterpret_cast<scene::IAnimatedMeshSceneNode*>(getNode())->setMD2Animation(animationType);
	if(loopMode == false)
	{
		node->setFrameLoop(node->getStartFrame(), node->getEndFrame()-3); // what the fuck am I coding
	}
	
	animation = animationType;
}

scene::EMD2_ANIMATION_TYPE MovingObject::getAnimation()
{
	return animation;
}
